package com.caidanxiaoyuan.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.faces.application.Application;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.caidanxiaoyuan.util.ResponseUtil;
import com.caidanxiaoyuan.util.VersionConfUtil;

@Controller
@RequestMapping("/version")
public class VersionController {

	@RequestMapping("/update")
	public String update(int version, HttpServletRequest request, HttpServletResponse response) {
		if (version < Integer.parseInt(VersionConfUtil.getValue("version"))) {
			return "notify/update";
		} else {
			return "notify/update";
		}
	}
}

	/*public static void downloadAPK(HttpServletResponse response) throws IOException {
		File f = new File(Application.getRealPath("test.jsp") );
	    OutputStream out = response.getOutputStream();
	    BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
	    byte[] buf = new byte[1024];
	    int len = 0;
	
	    response.reset(); // 非常重要
	    response.setContentType("application/x-msdownload");
	    response.setHeader("Content-Disposition", "attachment; filename=" + "caidan360.apk");

    while ((len = br.read(buf)) > 0)
        out.write(buf, 0, len);
    br.close();
    out.close();
   }*/
